﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Terraria.Graphics.Effects
{
	// Token: 0x020003A1 RID: 929
	public class SkyManager : EffectManager<CustomSky>
	{
		// Token: 0x06002099 RID: 8345 RVA: 0x0045CC0C File Offset: 0x0045AE0C
		public void Reset()
		{
			foreach (CustomSky customSky in this._effects.Values)
			{
				customSky.Reset();
			}
			this._activeSkies.Clear();
		}

		// Token: 0x0600209A RID: 8346 RVA: 0x0045CC70 File Offset: 0x0045AE70
		public void Update(GameTime gameTime)
		{
			LinkedListNode<CustomSky> next;
			for (LinkedListNode<CustomSky> linkedListNode = this._activeSkies.First; linkedListNode != null; linkedListNode = next)
			{
				CustomSky value = linkedListNode.Value;
				next = linkedListNode.Next;
				value.Update(gameTime);
				if (!value.IsActive())
				{
					this._activeSkies.Remove(linkedListNode);
				}
			}
		}

		// Token: 0x0600209B RID: 8347 RVA: 0x00016F18 File Offset: 0x00015118
		public void Draw(SpriteBatch spriteBatch)
		{
			this.DrawDepthRange(spriteBatch, float.MinValue, float.MaxValue);
		}

		// Token: 0x0600209C RID: 8348 RVA: 0x00016F2B File Offset: 0x0001512B
		public void DrawToDepth(SpriteBatch spriteBatch, float minDepth)
		{
			if (this._lastDepth <= minDepth)
			{
				return;
			}
			this.DrawDepthRange(spriteBatch, minDepth, this._lastDepth);
			this._lastDepth = minDepth;
		}

		// Token: 0x0600209D RID: 8349 RVA: 0x0045CCBC File Offset: 0x0045AEBC
		public void DrawDepthRange(SpriteBatch spriteBatch, float minDepth, float maxDepth)
		{
			foreach (CustomSky customSky in this._activeSkies)
			{
				customSky.Draw(spriteBatch, minDepth, maxDepth);
			}
		}

		// Token: 0x0600209E RID: 8350 RVA: 0x00016F4C File Offset: 0x0001514C
		public void DrawRemainingDepth(SpriteBatch spriteBatch)
		{
			this.DrawDepthRange(spriteBatch, float.MinValue, this._lastDepth);
			this._lastDepth = float.MinValue;
		}

		// Token: 0x0600209F RID: 8351 RVA: 0x00016F6B File Offset: 0x0001516B
		public void ResetDepthTracker()
		{
			this._lastDepth = float.MaxValue;
		}

		// Token: 0x060020A0 RID: 8352 RVA: 0x00016F78 File Offset: 0x00015178
		public void SetStartingDepth(float depth)
		{
			this._lastDepth = depth;
		}

		// Token: 0x060020A1 RID: 8353 RVA: 0x00016F81 File Offset: 0x00015181
		public override void OnActivate(CustomSky effect, Vector2 position)
		{
			this._activeSkies.Remove(effect);
			this._activeSkies.AddLast(effect);
		}

		// Token: 0x060020A2 RID: 8354 RVA: 0x0045CD14 File Offset: 0x0045AF14
		public Color ProcessTileColor(Color color)
		{
			foreach (CustomSky customSky in this._activeSkies)
			{
				color = customSky.OnTileColor(color);
			}
			return color;
		}

		// Token: 0x060020A3 RID: 8355 RVA: 0x0045CD6C File Offset: 0x0045AF6C
		public float ProcessCloudAlpha()
		{
			float num = 1f;
			foreach (CustomSky customSky in this._activeSkies)
			{
				num *= customSky.GetCloudAlpha();
			}
			return MathHelper.Clamp(num, 0f, 1f);
		}

		// Token: 0x060020A4 RID: 8356 RVA: 0x0045CDD8 File Offset: 0x0045AFD8
		internal void DeactivateAll()
		{
			foreach (string key in this._effects.Keys)
			{
				if (base[key].IsActive())
				{
					base[key].Deactivate(new object[0]);
				}
			}
		}

		// Token: 0x04003D2B RID: 15659
		public static SkyManager Instance = new SkyManager();

		// Token: 0x04003D2C RID: 15660
		private float _lastDepth;

		// Token: 0x04003D2D RID: 15661
		private LinkedList<CustomSky> _activeSkies = new LinkedList<CustomSky>();
	}
}
